//
//  SeniorityTableViewCell.m
//  NewMusic
//
//  Created by chuxinyu123 on 15/11/14.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "SeniorityTableViewCell.h"
#import <UIImageView+WebCache.h>
#import <SDWebImageManager.h>
@implementation SeniorityTableViewCell

- (void)dealloc
{
    [_firstLabel release];
    [_secondLabel release];
    [_thirdLabel release];
    [_arrowImageView release];
    [_mainImageView release];
    [_titleLabel release];
    [_tableclothView release];
    [_upImageView release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self buildCell];
    }
    return self;
}

- (void)buildCell
{
    self.firstLabel = [[UILabel alloc] init];
    self.firstLabel.font = [UIFont systemFontOfSize:15];
    self.secondLabel = [[UILabel alloc] init];
    self.secondLabel.font = [UIFont systemFontOfSize:15];
    self.thirdLabel = [[UILabel alloc] init];
    self.thirdLabel.font = [UIFont systemFontOfSize:15];
    self.firstLightLabel = [[UILabel alloc] init];
    self.firstLightLabel.font = [UIFont systemFontOfSize:13];
    self.secondLightLabel = [[UILabel alloc] init];
    self.secondLightLabel.font = [UIFont systemFontOfSize:13];
    self.thirdLightLabel = [[UILabel alloc] init];
    self.thirdLightLabel.font = [UIFont systemFontOfSize:13];
    
  
    self.mainImageView = [[UIImageView alloc] init];
    self.upImageView = [[UIImageView alloc] init];
    self.tableclothView = [[UIView alloc] init];
    self.arrowImageView = [[UIImageView alloc] init];
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.textColor = [UIColor whiteColor];
    
    
    [self.contentView addSubview:_tableclothView];
    [self.contentView addSubview:_mainImageView];
    [self.contentView addSubview:_upImageView];
    [self.contentView addSubview:_titleLabel];
    [self.contentView addSubview:_firstLabel];
    [self.contentView addSubview:_secondLabel];
    [self.contentView addSubview:_thirdLabel];
    
    [self.contentView addSubview:_firstLightLabel];
    [self.contentView addSubview:_secondLightLabel];
    [self.contentView addSubview:_thirdLightLabel];
    [self.contentView addSubview:_arrowImageView];

   
    
    [_firstLabel release];
    [_secondLabel release];
    [_thirdLabel release];
    [_mainImageView release];
    [_tableclothView release];
    [_arrowImageView release];
    [_titleLabel release];
    [_upImageView release];
    [_firstLightLabel release];
    [_secondLightLabel release];
    [_thirdLightLabel release];

}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.tableclothView.frame = CGRectMake(10, 0, 375 - 20, self.frame.size.height - 10);
    self.mainImageView.frame = CGRectMake(10, 0, 120, _tableclothView.frame.size.height);
    self.upImageView.frame = _mainImageView.frame;
    self.titleLabel.frame = CGRectMake(10, 0, _mainImageView.frame.size.width, 30);
    self.firstLabel.frame = CGRectMake(140 + 5, 0, [SeniorityTableViewCell computeLenght:_firstLabel.text andFont:[UIFont systemFontOfSize:15]], self.tableclothView.frame.size.height / 3);
    self.firstLightLabel.frame = CGRectMake(_firstLabel.frame.size.width + _firstLabel.frame.origin.x, 0, 60, _firstLabel.frame.size.height);
   
    self.secondLabel.frame = CGRectMake(140 + 5, _firstLabel.frame.size.height + _firstLabel.frame.origin.y, [SeniorityTableViewCell computeLenght:_secondLabel.text andFont:[UIFont systemFontOfSize:15]], self.tableclothView.frame.size.height / 3);
    self.secondLightLabel.frame = CGRectMake(_secondLabel.frame.size.width + _secondLabel.frame.origin.x, _secondLabel.frame.origin.y, 60, _secondLabel.frame.size.height);
    
    
    self.thirdLabel.frame = CGRectMake(140 + 5, _secondLabel.frame.size.height + _secondLabel.frame.origin.y, [SeniorityTableViewCell computeLenght:_thirdLabel.text andFont:[UIFont systemFontOfSize:15]], self.tableclothView.frame.size.height / 3);
    self.thirdLightLabel.frame = CGRectMake(_thirdLabel.frame.size.width + _thirdLabel.frame.origin.x, _thirdLabel.frame.origin.y, 60, _thirdLabel.frame.size.height);
    
    
    self.arrowImageView.frame = CGRectMake(375 - 40, (self.frame.size.height - 20) / 2, 20, 20);
}
//计算字符串长度
+ (CGFloat)computeLenght:(NSString *)text andFont:(UIFont *)font
{
     CGRect authorRect = [text boundingRectWithSize:CGSizeMake(320, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName, nil] context:nil];
    return authorRect.size.width;
}

- (void)setSeniorityDataModel:(SeniorityDataModel *)seniorityDataModel
{
    if (_seniorityDataModel != seniorityDataModel) {
        [_seniorityDataModel release];
        _seniorityDataModel = [seniorityDataModel retain];
    }
    if (seniorityDataModel.songs.count == 3) {
    _titleLabel.text = seniorityDataModel.title;
    _firstLabel.text = [NSString stringWithFormat:@"1 %@ - ", [[seniorityDataModel.songs objectAtIndex:0] name]];
    _firstLabel.textColor = [UIColor whiteColor];
    
    _firstLightLabel.text = [[seniorityDataModel.songs objectAtIndex:0] singerName];
    _firstLightLabel.textColor = [UIColor grayColor];

    NSLog(@"%ld", seniorityDataModel.songs.count);
    _secondLabel.text = [NSString stringWithFormat:@"2 %@ - ", [[seniorityDataModel.songs objectAtIndex:1] name]];
    _secondLabel.textColor = [UIColor whiteColor];
    _secondLightLabel.text = [[seniorityDataModel.songs objectAtIndex:1] singerName];
    _secondLightLabel.textColor = [UIColor grayColor];
 
    _thirdLabel.text = [NSString stringWithFormat:@"3 %@ - ", [[seniorityDataModel.songs objectAtIndex:2] name]];
    _thirdLabel.textColor = [UIColor whiteColor];
    _thirdLightLabel.text = [[seniorityDataModel.songs objectAtIndex:2] singerName];
    _thirdLightLabel.textColor = [UIColor grayColor];
    }
    
    [_mainImageView sd_setImageWithURL:[NSURL URLWithString:seniorityDataModel.image]];
    _arrowImageView.backgroundColor = [UIColor clearColor];
    _arrowImageView.image = [UIImage imageNamed:@"BF-you"];
    _tableclothView.backgroundColor = [UIColor whiteColor];
    _tableclothView.alpha = 0.05;
    _upImageView.backgroundColor = [UIColor blackColor];
    _upImageView.alpha = 0.1;
    }

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
